import * as echarts from 'echarts'
import { useEffect, useRef } from 'react';
//封装echarts组件
function Bar ({title,xData,yData,style}) {
    const domRef = useRef()
    //初始化 echarts
    const chartInit = () => {
        // 基于准备好的dom，初始化echarts实例
        const myChart = echarts.init(domRef.current);
        // 绘制图表
        myChart.setOption({
            title: {
                text: title
            },
            tooltip: {},
            xAxis: {
                data: xData
            },
            yAxis: {},
            series: [
                {
                    name: '销量',
                    type: 'bar',
                    data: yData
                }
            ]
        });
    }

    //执行初始化函数
    useEffect(()=>{
        chartInit()
    })
    return (
        <diV ref={domRef} style={style}>Home</diV>
    )
}
export default Bar